// The following is derived from https://github.com/primer/tooltips
// The MIT License (MIT)
// Copyright (c) 2016 GitHub Inc.

$tooltip-max-width: 250px !default;
$tooltip-background-color: transparentize($black, 0.3) !default;
$tooltip-text-color: $white !default;
$tooltip-delay: 0.4s !default;
$tooltip-duration: 0.1s !default;

.tooltipped {
  position: relative;
  cursor: pointer;
}

// This is the tooltip bubble
.tooltipped::after {
  content: attr(aria-label);
  position: absolute;
  z-index: 1000000;
  display: none;
  padding: 5px 8px;
  font-size: $base-font-size;
  font-weight: normal;
  -webkit-font-smoothing: subpixel-antialiased;
  color: $tooltip-text-color;
  text-align: center;
  text-decoration: none;
  text-shadow: none;
  text-transform: none;
  letter-spacing: normal;
  word-wrap: break-word;
  white-space: pre;
  pointer-events: none;
  background: $tooltip-background-color;
  border-radius: 2px;
  opacity: 0;
}

// This is the tooltip arrow
.tooltipped::before {
  position: absolute;
  z-index: 1000001;
  display: none;
  width: 0;
  height: 0;
  color: $tooltip-background-color;
  pointer-events: none;
  content: "";
  border: 5px solid transparent;
  opacity: 0;
}

// delay animation for tooltip
@keyframes tooltip-appear {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

// This will indicate when we'll activate the tooltip
.tooltipped:hover,
.tooltipped:active,
.tooltipped:focus,
.tooltipped-immediate {
  &::before,
  &::after {
    display: inline-block;
    text-decoration: none;
    animation-name: tooltip-appear;
    animation-duration: $tooltip-duration;
    animation-fill-mode: forwards;
    animation-timing-function: ease-in;
    animation-delay: $tooltip-delay;
  }
}

.tooltipped-no-delay:hover,
.tooltipped-no-delay:active,
.tooltipped-no-delay:focus {
  &::before,
  &::after {
    opacity: 1;
    animation: none;
  }
}

.tooltipped-multiline:hover,
.tooltipped-multiline:active,
.tooltipped-multiline:focus {
  &::after {
    display: table-cell;
  }
}

// Tooltipped south
.tooltipped-s,
.tooltipped-se,
.tooltipped-sw {
  &::after {
    top: 100%;
    right: 50%;
    margin-top: 5px;
  }

  &::before {
    top: auto;
    right: 50%;
    bottom: -5px;
    margin-right: -5px;
    border-bottom-color: $tooltip-background-color;
  }
}

.tooltipped-se {
  &::after {
    right: auto;
    left: 50%;
    margin-left: -($spacing-unit / 2);
  }
}

.tooltipped-sw::after {
  margin-right: -($spacing-unit / 2);
}

// Tooltips above the object
.tooltipped-n,
.tooltipped-ne,
.tooltipped-nw {
  &::after {
    right: 50%;
    bottom: 100%;
    margin-bottom: 5px;
  }

  &::before {
    top: -5px;
    right: 50%;
    bottom: auto;
    margin-right: -5px;
    border-top-color: $tooltip-background-color;
  }
}

.tooltipped-ne {
  &::after {
    right: auto;
    left: 50%;
    margin-left: -($spacing-unit / 2);
  }
}

.tooltipped-nw::after {
  margin-right: -($spacing-unit / 2);
}

// Move the tooltip body to the center of the object.
.tooltipped-s::after,
.tooltipped-n::after {
  transform: translateX(50%);
}

// Tooltipped to the left
.tooltipped-w {
  &::after {
    right: 100%;
    bottom: 50%;
    margin-right: 5px;
    transform: translateY(50%);
  }

  &::before {
    top: 50%;
    bottom: 50%;
    left: -5px;
    margin-top: -5px;
    border-left-color: $tooltip-background-color;
  }
}

// tooltipped to the right
.tooltipped-e {
  &::after {
    bottom: 50%;
    left: 100%;
    margin-left: 5px;
    transform: translateY(50%);
  }

  &::before {
    top: 50%;
    right: -5px;
    bottom: 50%;
    margin-top: -5px;
    border-right-color: $tooltip-background-color;
  }
}